<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="Content-Language" content="zh-CN"><link href="stylesheet.css" media="all" rel="stylesheet" type="text/css">
<title>pg_constraint</title>
<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?d286c55b63a3c54a1e43d10d4c203e75"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script>
</head><body class="SECT1">
<div>
<table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><th colspan="5" align="center" valign="bottom">PostgreSQL 8.2.3 中文文档</th></tr>
<tr><td width="10%" align="left" valign="top"><a href="catalog-pg-class.html" accesskey="P">后退</a></td><td width="10%" align="left" valign="top"><a href="catalogs.html">快退</a></td><td width="60%" align="center" valign="bottom">章43. 系统表</td><td width="10%" align="right" valign="top"><a href="catalogs.html">快进</a></td><td width="10%" align="right" valign="top"><a href="catalog-pg-conversion.html" accesskey="N">前进</a></td></tr>
</table>
<hr align="LEFT" width="100%"></div>
<div class="SECT1"><h1 class="SECT1"><a name="CATALOG-PG-CONSTRAINT">43.13. <tt class="STRUCTNAME">pg_constraint</tt></a></h1><a name="AEN63057"></a>
<p><tt class="STRUCTNAME">pg_constraint</tt> 存储表上的检查约束、主键、唯一约束和外键约束。字段约束不会得到特殊对待。每个字段约束都等效于某些表约束。非空约束记录在 <tt class="STRUCTNAME">pg_attribute</tt> 表中。</p>
<p>在域上面的检查约束也存储在这里。</p>
<div class="TABLE"><a name="AEN63063"></a>
<p><b>表43-13. <tt class="STRUCTNAME">pg_constraint</tt> 字段</b></p>
<table border="1" class="CALSTABLE"><col><col><col><col>
<thead>
<tr><th>名字</th><th>类型</th><th>引用</th><th>描述</th></tr>
</thead>
<tbody>
<tr><td><tt class="STRUCTFIELD">conname</tt></td><td><tt class="TYPE">name</tt></td><td>&nbsp;</td><td>约束名字(不一定是唯一的)</td></tr>
<tr><td><tt class="STRUCTFIELD">connamespace</tt></td><td><tt class="TYPE">oid</tt></td><td><tt class="LITERAL"><a href="catalog-pg-namespace.html"><tt class="STRUCTNAME">pg_namespace</tt></a>.oid</tt></td><td>包含这个约束的名字空间的 OID</td></tr>
<tr><td><tt class="STRUCTFIELD">contype</tt></td><td><tt class="TYPE">char</tt></td><td>&nbsp;</td><td><tt class="LITERAL">c</tt> = 检查约束， <tt class="LITERAL">f</tt> = 外键约束， <tt class="LITERAL">p</tt> = 主键约束， <tt class="LITERAL">u</tt> = 唯一约束</td></tr>
<tr><td><tt class="STRUCTFIELD">condeferrable</tt></td><td><tt class="TYPE">bool</tt></td><td>&nbsp;</td><td>这个约束可以推迟吗?</td></tr>
<tr><td><tt class="STRUCTFIELD">condeferred</tt></td><td><tt class="TYPE">bool</tt></td><td>&nbsp;</td><td>缺省时这个约束是否推迟的?</td></tr>
<tr><td><tt class="STRUCTFIELD">conrelid</tt></td><td><tt class="TYPE">oid</tt></td><td><tt class="LITERAL"><a href="catalog-pg-class.html"><tt class="STRUCTNAME">pg_class</tt></a>.oid</tt></td><td>这个约束所在的表；如果不是表约束则为 0</td></tr>
<tr><td><tt class="STRUCTFIELD">contypid</tt></td><td><tt class="TYPE">oid</tt></td><td><tt class="LITERAL"><a href="catalog-pg-type.html"><tt class="STRUCTNAME">pg_type</tt></a>.oid</tt></td><td>这个约束所在的域；如果不是一个域约束则为 0</td></tr>
<tr><td><tt class="STRUCTFIELD">confrelid</tt></td><td><tt class="TYPE">oid</tt></td><td><tt class="LITERAL"><a href="catalog-pg-class.html"><tt class="STRUCTNAME">pg_class</tt></a>.oid</tt></td><td>如果是外键，则为参考的表；否则为 0</td></tr>
<tr><td><tt class="STRUCTFIELD">confupdtype</tt></td><td><tt class="TYPE">char</tt></td><td>&nbsp;</td><td>外键更新动作代码</td></tr>
<tr><td><tt class="STRUCTFIELD">confdeltype</tt></td><td><tt class="TYPE">char</tt></td><td>&nbsp;</td><td>外键删除动作代码</td></tr>
<tr><td><tt class="STRUCTFIELD">confmatchtype</tt></td><td><tt class="TYPE">char</tt></td><td>&nbsp;</td><td>外键匹配类型</td></tr>
<tr><td><tt class="STRUCTFIELD">conkey</tt></td><td><tt class="TYPE">int2[]</tt></td><td><tt class="LITERAL"><a href="catalog-pg-attribute.html"><tt class="STRUCTNAME">pg_attribute</tt></a>.attnum</tt></td><td>如果是表约束，则是约束控制的字段列表</td></tr>
<tr><td><tt class="STRUCTFIELD">confkey</tt></td><td><tt class="TYPE">int2[]</tt></td><td><tt class="LITERAL"><a href="catalog-pg-attribute.html"><tt class="STRUCTNAME">pg_attribute</tt></a>.attnum</tt></td><td>如果是一个外键，是参考的字段的列表</td></tr>
<tr><td><tt class="STRUCTFIELD">conbin</tt></td><td><tt class="TYPE">text</tt></td><td>&nbsp;</td><td>如果是检查约束，那就是其表达式的内部形式</td></tr>
<tr><td><tt class="STRUCTFIELD">consrc</tt></td><td><tt class="TYPE">text</tt></td><td>&nbsp;</td><td>如果是检查约束，则是表达式的人类可读形式</td></tr>
</tbody>
</table>
</div>
<div class="NOTE">
<blockquote class="NOTE">
<p><b>【注意】</b> <tt class="STRUCTFIELD">consrc</tt> 在被引用的对象改变之后不会被更新，它不会跟踪字段的名字修改。与其依赖这个字段，最好还是使用 <code class="FUNCTION">pg_get_constraintdef()</code> 来抽取一个检查约束的定义。</p>
</blockquote>
</div>
<div class="NOTE">
<blockquote class="NOTE">
<p><b>【注意】</b> <tt class="LITERAL">pg_class.relchecks</tt> 需要和在此表上为给定关系找到的检查约束的数目一致。</p>
</blockquote>
</div>
</div>
<div>
<hr align="LEFT" width="100%">
<table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td width="33%" align="left" valign="top"><a href="catalog-pg-class.html" accesskey="P">后退</a></td><td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">首页</a></td><td width="33%" align="right" valign="top"><a href="catalog-pg-conversion.html" accesskey="N">前进</a></td></tr>
<tr><td width="33%" align="left" valign="top"><tt class="STRUCTNAME">pg_class</tt></td><td width="34%" align="center" valign="top"><a href="catalogs.html" accesskey="U">上一级</a></td><td width="33%" align="right" valign="top"><tt class="STRUCTNAME">pg_conversion</tt></td></tr>
</table>
</div>
</body></html>